



	
use Data/Estimation_sample.dta, clear
	
	gen nexis_buildings  = ROOFME/PROOFME
		
		
	gen roofratio = ROOFME/ROOFTI
	gen roofratiobuildings = roofratio*nexis_buildings
		
	gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

	
		

		
		xi: xtivreg2 cuminst roofrelativeIV  i.quarter  [aweight =NCust	], fe cluster(postcode) 
		
		predict ehat , e
		
		
		
		gen cumhat = cum - ehat
		
		
collapse (mean) cuminst green_p *ROOFTI* *ROOFME* *roof* cumhat NCustomermean=NCustomer   [weight=NCustomer], by(postcode)

*merge with map data
merge m:1 postcode using Data/PostcodeArea.dta
	drop _merge
	
	
merge m:1 postcode using Data/SA3postcode.dta
drop _merge
merge m:1 SA3_CODE16 using "data/maps/sa3" 

keep if _merge ==3
drop _merge
*  melbourne

gen Melbourne = 1 if SA4_CODE=="213" | SA4_CODE =="210" | SA4_CODE=="209" | SA4_CODE =="207" | SA4_CODE=="211"  | SA4_CODE=="208" | SA4_CODE=="206" | SA4_CODE=="212"
replace Melbourne =0 if Melbourne ==.

gen Mornington = 1 if SA4_CODE =="214"
replace Mornington = 0 if Mornington ==.

gen Geelong = 1 if SA4_CODE=="203"
replace Geelong = 0 if Geelong ==.


gen Country = 1 if Melbourne ==0 & Mornington == 0 & Geelong==0
replace Country =0 if Country==.


merge m:1 postcode using Data/Postcode_matching.dta
keep if _merge ==3
drop _merge


	
	
keep if id 	<=1380 & id> 683 // keep Vic only 

	replace cuminst = round(cumins,.01)
	replace green = round(green_plan, 0.005)
	replace cumhat = round(cumhat,0.01)
	
	replace roofratiobuildings = round(roofratiobuildings,1)
	replace roofratio = round(roofratio,1)
	replace roofrelativeIV = round(roofrelativeIV, 1)

	
	replace NCustomer = round(NCustomer,1)
		
		
		


spmap cuminst using Data/poa_coord if Melbourne ==1, id(id) fcolor(Reds2)  ndfcolor(white) ///
ndocolor(white)  clmethod(custom) clbreaks(0 0.03 0.05 0.09 0.11 0.165 0.2 0.23 0.36 0.58 3.5 )  osize(0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt) ocolor(white 			white white white white white white white white white )   mosize(none) mocolor(gs8) scalebar(units(10) scale(89.5)  label(Kilometers) xpos(100))  ///
legend(size(8pt) pos(2)) point(data("Data/GPO.dta") xcoord(x) ycoord(y) size(medlarge) fcolor(gs0) ocolor(white) osize(1.5pt))

graph export Analysis/cummapMelb_pcode.png, replace

spmap green_p using Data/poa_coord if Melbourne ==1 , id(id) fcolor(Greens2)  ndfcolor(white) ///
ndocolor(white)  clmethod(custom) clbreaks(0 0.01 0.015 0.03 0.035 0.045 0.055 0.065 0.09 0.125 1 )  osize(0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt 0.001pt) ocolor(white 			white white white white white white white white white )   mosize(none) mocolor(gs8) scalebar(units(10) scale(89.5)  label(Kilometers) xpos(100))  ///
legend(size(8pt) pos(2)) point(data("Data/GPO.dta") xcoord(x) ycoord(y) size(medlarge) fcolor(gs0) ocolor(white) osize(1.5pt))

graph export Analysis/greenmapMelb_pcode.png, replace
